﻿
var zqnb = zqnb || {};
(function () {
    "use strict";

    var commonApp = zqnb.commonApp;

    commonApp.controller('loginController', ['$scope','$http', function ($scope, $http) {

        var slef = this;
        var loginReturn = function () {
            window.location.href = slef.returnUrl ? slef.returnUrl : "/";
        };

        $scope.message  = "用户登录";
        $scope.user = { IdentityName: '', Password: '', RememberMe: false, Site: "" };
        $scope.login = function () {

            var loginPostUrl = zqnb.route.makeUrl("common", "account", "AjaxLogin");

            $http.post(loginPostUrl, $scope.user)
                .success(function (data) {
                    if (data.Success) {
                        $scope.message = data.message;
                        loginReturn();
                    }
                    else {
                        $scope.message = data.Message;
                        console.log(data);
                    }
                });
        };
    }]);

    zqnb.utils.setFocus("loginButton");

    ////默认焦点
    //document.onkeydown = function (event_e) {
    //    if (window.event) event_e = window.event;
    //    var int_keycode = event_e.charCode || event_e.keyCode;
    //    if (int_keycode == '13') {

    //        document.getElementById("loginButton").focus();;
    //    }
    //};

}());

//angular.module("loginSingleApp", ['ui.bootstrap'])
//    .controller("singleCtrl", function ($scope, $http) {
//        $scope.loginName = { type : "2", name : "账号" };
//        $scope.items = [
//            { type : "2", name : "帐号" },
//            { type : "1", name : "Email" },
//            { type : "0", name : "账号，学校" }
//        ];

//        $scope.selectMark = function (loginName){
//            $scope.loginName.name = loginName.name;
//            $scope.loginName.type = loginName.type;
//            if ($scope.loginName.type != "0") {
//                $scope.user.Domain = "";
//            }
//        }

//        $scope.user = { IdentityName : '', Password : '', RememberMe : false, Domain : "" };
//        $scope.isType0 = function (){
//            return $scope.loginName.type == "0";
//        }
//        $scope.isType1 = function (){
//            return $scope.loginName.type == "1";

//        }
//        $scope.isType2 = function (){
//            return $scope.loginName.type == "2";

//        }

//        $scope.TaskRemaining = function (){
//            return !$scope.user.Password || !$scope.user.IdentityName || $scope.user.IdentityName == '账号/Email/(帐号，学校)';

//        };
//        $scope.dialogLogin = function (){
//            var accountArray = $scope.user.IdentityName;
//            if (accountArray.split('@').length >= 2) {
//                accountParam = '1,' + accountArray;
//            }
//            else {
//                accountParam = '0,' + accountArray;
//            }

//            $http.post('/Common/Account/AjaxLogin', { IdentityName : accountParam, Password : $scope.user.Password, RememberMe : $scope.user.RememberMe })
//                .success(function (data) {
//                    if (data.Success) {
//                        $scope.user.IdentityName = '账号/Email/(帐号，学校)';
//                        jBox.tip(data.Message, 'info');
//                        window.location.href = $scope.myreturnUrl ? $scope.myreturnUrl : "/";
//                    }
//                    else {
//                        jBox.tip(data.Message, 'info');
//                    }
//                });
//        };
//        $scope.loginReturn = function (){
//            window.location.href = $scope.myreturnUrl ? $scope.myreturnUrl : "/";
//        }

//    });
